
layui.config({
	version:'1510164124181'
}).use(['form','laydate', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
	laydate = layui.laydate;//日期
	laypage = layui.laypage;//分页
	element = layui.element; //元素操作
	pageSize=100;
	inituserdata();
    let option = {
        theme:'default',
        expandLevel : 1,
        beforeExpand : function($treeTable, id) {
            //判断id是否已经有了孩子节点，如果有了就不再加载，这样就可以起到缓存的作用
            let info ="";
            if ($('.' + id, $treeTable).length) { return; }
            let Names=$("#Names").val();
            let level=$("#level option:selected").val();
            $.ajax({
                url: httpurl+"/SelectMenuInfo",
                cache: false,
                async:false,
				headers: {
					"Access-Control-Allow-Origin": "*",
					"Access-Control-Allow-Methods": "*",
					"Access-Control-Allow-Headers": "Authorization",
					"Authorization": GetTokenInfo()
				},
				contentType : 'application/json',
                data: {
                    "Names":Names,
                    "level":level,
                    "page":pageNo,
                    "pagesize":pageSize,
                    "parentid":id,
                },
                // dataType: "json",
                success: function(data) {
                    // console.log("SelectMenuInfo===children="+JSON.stringify(data));
					if(data.rtnCode==200){
						let dataInfo=data.data.list;
						for(let i=0;i<dataInfo.length;i++) {
							let boolean_info = "";
							if (dataInfo[i].isHasChild != 0) {
								boolean_info = 'haschild="true"';
							} else {
								boolean_info = 'isLastOne="true"';
							}
							console.log(dataInfo[i].parentId);
							info += '<tr id="' + dataInfo[i].id + '" pId="'+dataInfo[i].parentId+'"  ' + boolean_info + ' >' +
								'<td>' + dataInfo[i].menu_name + '</td>' +
								'<td>' + dataInfo[i].url + '</td>' +
								'<td>' +
								'<a href="AddMeau.html?meauId='+dataInfo[i].id+'">查看</a>&nbsp;&nbsp;&nbsp;' +
								'<a href="#" data-id="'+dataInfo[i].id+'" data-info="deleteMenu" onclick="DeleteInfo(this);">删除</a>' +
								'</td>' +
								'</tr>';

						}
						$treeTable.addChilds(info);
					}

                }
            });
        },
        onSelect : function($treeTable, id) {
            window.console && console.log('onSelect:' + id);
        }
    };
    $('#TableInfo').treeTable(option);
});

function inituserdata(){
	let Names=$("#Names").val();
	let level=$("#level option:selected").val();
	$.ajax({
		url: httpurl+"/SelectMenuInfo",
		cache: false,
        async:false,
		data: {
			"Names":Names,
			"level":level,
			"page":pageNo,
			"pagesize":pageSize,
			"parentid":0,
		},
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		success: function(data) {
			let info="";
			if(data.rtnCode==200){
				let dataInfo=data.data.list;
				totalRecords = data.data.total;
				for(let i=0;i<dataInfo.length;i++) {
					let boolean_info = "";
					if (dataInfo[i].isHasChild != 0) {
						boolean_info = 'haschild="true"';
					} else {
						boolean_info = 'isLastOne="true"';
					}
					info += '<tr id="' + dataInfo[i].id + '" controller="true" class="parent_info"  ' + boolean_info + ' >' +
								'<td>' + dataInfo[i].menu_name + '</td>' +
								'<td>' + dataInfo[i].url + '</td>' +
								'<td>' +
									'<a href="AddMeau.html?meauId='+dataInfo[i].id+'">查看</a>&nbsp;&nbsp;&nbsp;' +
									'<a href="#" data-id="'+dataInfo[i].id+'" data-info="deleteMenu" onclick="DeleteInfo(this);">删除</a>' +
								'</td>' +
							'</tr>';
				}
			}else{
				totalRecords =0;
				info += '<tr>'
				+'<td colspan="8" style="text-align:center;">暂无数据</td>'
				+'</tr>';
			}
			$("#TableInfo tbody").html(info);
			pageLayPage("inituserdata");
		}

	});
}
function SearchInfo() {
	pageNo=1;
	inituserdata();
}

function onloadInfo(){
	SearchInfo()
}